package com.cwx.config;

import com.cwx.interceptor.LoginInterceptor;
import com.cwx.utils.Tool;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import java.security.NoSuchAlgorithmException;

/**
 * Created by code on 17-8-30.
 */
@Configuration
public class WebAppConfigurer extends WebMvcConfigurerAdapter{
    /**
     * 添加拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        // 注册登录拦截器
        InterceptorRegistration loginReg = registry.addInterceptor(new LoginInterceptor());
        loginReg.addPathPatterns("/member/**","/toMain","/orderInfo/**","/wechat/**");//  待加入
        loginReg.excludePathPatterns("/member/toApply/**","/member/next","/member/invalid","/member/success","/orderInfo/apply/**");
        loginReg.excludePathPatterns("/wechat/toLogin","/wechat/bind","/wechat/login","/wechat/retrievePwd","/wechat/index","/wechat/loginPage","/wechat/registerPage","/wechat/toBind");
        super.addInterceptors(registry);
    }

    public static void main(String[] args) throws NoSuchAlgorithmException {
//        MessageDigest md5 = MessageDigest.getInstance("MD5");
//        System.out.println(Tool.Encrypt("ss","MD5","utf-8"));
        System.out.println(Tool.encoderByMd5("cwx00!96532"));
    }
}